#ifndef CASHCONTEXT_H
#define CASHCONTEXT_H

#include "cashfactory.h"

#include <stdexcept>

class CashContext
{
public:
    CashContext(int mode)
    : mode(mode)
    {}

    double calculate(double price, int count)
    {
        Cash *cash = CashFactory::createCashMode(mode);
        double result = cash->payCash(price, count);

        if (cash != nullptr)
        {
            delete cash;
            cash = nullptr;
        }

        return result;
    }

private:
    int mode;
};

#endif